package com.xjscrm.console.service.customer.groupSend.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.groupSend.BatchGroupSendJobDto;
import com.xjscrm.console.service.customer.groupSend.BatchSpeedGroupSendService;
import com.xjscrm.console.service.customer.groupSend.SpeedGroupSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BatchSpeedGroupSendServiceImpl implements BatchSpeedGroupSendService {

    @Autowired
    private SpeedGroupSendService speedGroupSendService;


    @Override
    public void batchcancelSpeedGroupSendJob(BatchGroupSendJobDto batchGroupSendJobDto) {
        if (batchGroupSendJobDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (batchGroupSendJobDto.getIds() == null || batchGroupSendJobDto.getIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id : batchGroupSendJobDto.getIds()) {
            try {
                batchGroupSendJobDto.setId(id);
                speedGroupSendService.cancelSpeedGroupSendJob(batchGroupSendJobDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchDeleSpeedGroupSendJob(BatchGroupSendJobDto batchGroupSendJobDto) {
        if (batchGroupSendJobDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (batchGroupSendJobDto.getIds() == null || batchGroupSendJobDto.getIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id : batchGroupSendJobDto.getIds()) {
            try {
                batchGroupSendJobDto.setId(id);
                speedGroupSendService.delSpeedGroupSendJob(batchGroupSendJobDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchConfirmSpeedGroupSendJob(BatchGroupSendJobDto batchGroupSendJobDto) {
        if (batchGroupSendJobDto.getMerId() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.MERID_NULL);
        }
        if (batchGroupSendJobDto.getIds() == null || batchGroupSendJobDto.getIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id : batchGroupSendJobDto.getIds()) {
            try {
                batchGroupSendJobDto.setId(id);
                speedGroupSendService.confirmSpeedGroupSendJob(batchGroupSendJobDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
